<template>
	<view>
		<!-- -->
		<view class="content" v-if="!pageLoading">

			<!-- <view class="top"> -->
			<!-- <u-navbar scrollable=false :placeholder='true' bgColor="#ffffff" :autoBack="true" title=""> -->
			<!-- <view slot="right" class="input_right flex">
						<u-input prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399"
							customStyle="background-color: #f5f5f5;" suffixIconStyle="color: #909399" border=""
							v-model="inputValue" >
						</u-input>
						<image src="/static/images/search/share.png" style="height: 48rpx;width: 48rpx;margin: 0 32rpx;"
							mode=""></image>
						<image src="/static/images/search/more.png"
							style="width: 48rpx;height: 48rpx;margin-right: 32rpx;position: relative;" mode=""></image>
						<view class="" v-show="showmodel" style="position: absolute;right: 40rpx;top: 80rpx;">
							<view class="li flex"
								style="line-height: 96rpx; width: 288rpx;height: 96rpx; background-color: white;"> 
								<text>首页</text>
							</view>
							<view class="li flex"
								style="line-height: 96rpx; width: 288rpx;height: 96rpx; background-color: white;">
		
								<text>购物车</text>
							</view>
							<view class="li flex"
								style="line-height: 96rpx; width: 288rpx;height: 96rpx; background-color: white;">
								<text>消息</text>
							</view>
							<view class="li flex"
								style="line-height: 96rpx; width: 288rpx;height: 96rpx; background-color: white;">
								<text>反馈/举报</text>
							</view>
						</view>
					</view> 
				</u-navbar>-->
			<u-navbar :placeholder="true" v-if="$store.state.company_status==0" bgColor="#fff" :autoBack="true" title="" height='80'
				leftIconColor="#333">
				<view class="" slot="center" style='width: 100%;'>
					<view style="width:100%;margin: 0 auto;background-color: #fff;height:76rpx;line-height: 76rpx;">
						<view class="searchBox flexJBC mt24" style="width: 100%;"
							@click="$my.go('/pages/search/index')">
						</view>
					</view>
					<Certification />
				</view>
			</u-navbar>
			<u-navbar class='item' v-else bgColor="#fff" :autoBack="true" :placeholder="true" title="" height='40' leftIconColor="#333">
			</u-navbar>
			<!-- </view> -->
			<!-- 商品失效 -->
			<view class="padding32" v-if="code==208">
				<view class="flexcenter flexRowCenter" style="height: 500rpx;">
					商品已失效
				</view>
				<List :list="shixiaoTuijianList" v-if="shixiaoTuijianList.length>0"></List>
			</view>
			<!-- 未失效 -->
			<view v-else>
				<!-- 轮播图 -->
				<view class="" v-if="swiperList.length>0 && !showCoupon && !showModel">
					<Swiper :list='swiperList' mode='number'></Swiper>
					<!-- <u-swiper :autoplay="false"  :list="swiperList" height="750rpx" radius="0rpx" keyName='image'
						@change="e => swiperCurrent = e.current">
						 <view slot="indicator" class="indicator-num" >
						     <text class="indicator-num__text">{{ swiperCurrent+1 }}/{{ swiperList.length }}</text>
						 </view>
					</u-swiper> -->
				</view>
				<!-- 发货与运费信息 -->
				<view class="container">
					<view class="whiteBox">
						<view class="flex">
							<view class="price homeRed fw5  fontS40" style="margin: 16rpx 0;"> ￥{{info.price}} </view>
							<view class="fontS24 co9" style="margin-left: 22rpx;">
								官方售价 <text style="text-decoration: line-through;">{{info.ot_price}}</text>
							</view>
						</view>
						<view style="line-height: 50rpx;padding-bottom: 10rpx;">
							<view class="title fw6 fontS32" style="min-height:80rpx;">
								<text>{{info.product_name}}</text>
								<text style="float: right;font-weight: 400;height:32rpx;" class="co9 fontS24">
									已售卖{{info.sales}}+
								</text>
							</view>
						</view>
					</view>
					<view class="whiteBox mt24" @click="showCoupon=true" v-if="info.coupon.length>0">
						<view class='flexJBC'>
							<view class="homeRed fontS24 elipes1" style="width: 80%;">
								<text v-for="(item,index) in info.coupon" :key="index"
									style="margin-right: 10rpx;">{{item.title}}</text>
							</view>
							<view class="fontS24 co3 flex">
								<text>领券</text>
								<u-icon name="arrow-right" color="#ccc" size="18rpx"></u-icon>
							</view>
						</view>
					</view>
					<view class="whiteBox mt24">
						<view class="li fontS24 co9">
							<text style="margin-right: 20rpx;">发货</text><text
								class="fontS28 co3">{{info.delivery_address }}</text>
						</view>
						<view class="li  fontS24 co9 mt24 flex" v-if="info.spec_type==1">
							<text style="margin-right: 20rpx;">规格</text>
							<view class="skuBox co3 fontS24 flex" @click="showModel=true;type=2">
								<text>{{info.attr_name_text}} 可选 </text>
								<u-icon name="arrow-right" style='margin-top: 2rpx;' color="#ccc" size='12'>
								</u-icon>
							</view>
							<!-- <text style="margin-right: 20rpx;">运费</text><text>￥{{info.free }} 预估</text> -->
						</view>
					</view>
					<!--商品评价 -->
					<view class="evaluate mb24"
						style="padding: 20rpx; background-color: white; margin-top: 24rpx; border-radius: 16rpx; ">
						<view class="co3 fontS28 flexJBC">
							<text>商品评价（{{findProductComment.total}}）</text>
							<u-icon name="arrow-right"
								@click="$my.go('/myPackageA/goodsAndFacton/evaluate/evaluate?type=2&id='+id)">
							</u-icon>
						</view>
						<view class="co9 fontS24" style="margin-top: 20rpx;" v-if="findProductComment.total==0">
							暂无有效评价
						</view>
						<view class="review  mt24" v-for="(item,index) in findProductComment.data" :key="index">
							<view class="li">
								<view class="li_box1 flexJBC">
									<view class="flex">
										<u-image :src="item.avatar" width='48rpx' height='48rpx' radius="24rpx">
										</u-image>
										<text class="name co9 fontS20"
											style="margin-left: 8rpx;">{{$my.hideName(item.nickname)}}</text>
									</view>
									<view class="">
										<u-rate readonly size="14" gutter="0" count="5" v-model="item.start"></u-rate>
									</view>
								</view>
								<view class="li_text" style="margin:8rpx 0 16rpx ;">
									{{item.comment_text}}
								</view>
								<!-- @click="$my.go('/myPackageA/goodsAndFacton/evaluate/comment?id='+item.id)" -->
								<view class=""
									@click="$my.go('/myPackageA/goodsAndFacton/evaluate/evaluate?type=2&id='+id)"
									style="padding: 0;">
									<view class="flex" style="flex-wrap: wrap;">
										<u-image
											:style="{marginRight:indexx==(4*indexx-1)?'0rpx':'17rpx',marginBottom:'20rpx'}"
											:src="itemm" width='144rpx' height='144rpx' radius="8rpx"
											v-for="(itemm,indexx) in item.image" :key="indexx" />
									</view>
								</view>
							</view>
						</view>
					</view>
					<!--  店铺信息 -->
					<view class="shop" v-if="info.store">
						<view class="li">
							<view class="li_top">
								<u-image style="" width="80rpx" height="80rpx" :src="info.store.store_image"
									radius="8rpx" />
								<view class="box_center">
									<view class="title co3 fw6">{{info.store.store_name}}</view>
									<view class="">
										<text class="score">{{info.store.postage_score}}分</text>
										<text class="deal co9">已成交{{info.store.pay_number}}</text>
									</view>
								</view>
								<view class="box_right"
									@click="$my.go(info.store.store_type==1?`/myPackageA/goodsAndFacton/store?store_id=${info.store_id}` : `/myPackageA/goodsAndFacton/store?store_id=${info.store_id}`)">
									<button class="entry fontS24">进店</button>
								</view>
							</view>
							<view class="li_center" v-if="info.store_product_data.length>0">
								<scroll-view @scroll="getstoreGoods(true)" scroll-x="true">
									<view class="flex" style="flex-wrap: nowrap;">
										<view v-for="(item, index) in info.store_product_data" :key="index"
											class="li_img"
											@click="$my.go('/myPackageA/goodsAndFacton/goodsDetails?id=' + item.id)">
											<u-image :src="item.image" width="190rpx" height="190rpx" radius="8rpx">
											</u-image>
											<view class="money">
												￥<text>{{item.price}}</text>
											</view>
										</view>
									</view>
								</scroll-view>
							</view>
						</view>
					</view>
				</view>
				<!-- 商品详情 -->
				<view class="mb24" style="background-color: #f5f5f5;">
					<view class="padding32 fontS32 " style="color: #000;">
						商品详情
					</view>
					<rich-text :nodes="info.content"></rich-text>
				</view>
				<!-- 底部按钮 -->
				<view class="bottom flex">
					<view class="flex" style="margin-right: 10%;">
						<view class="flexcenter" @click="follow">
							<u-icon :name="info.focus?'star-fill':'star'" :color="info.focus?'#DD2131':'#666'"
								size="48rpx"></u-icon>
							<view>{{info.focus?'已收藏':'收藏'}}</view>
						</view>
						<view class="flexcenter" style="margin-left:48rpx;" @click="gokefu">
							<u-icon name="server-man" size="48rpx" color="#666"></u-icon>
							<view>客服</view>
						</view>
					</view>
					<view class="bottom_btn flexJBC" style="flex: 1;">
						<u-button class="fontS28 fw5 cof add elipes1" @click="showModel=true;type=1" type="default">
							加入购物车
						</u-button>
						<u-button class="fontS28 fw5 cof topay " @click="showModel=true;type=2" type="default"
							customStyle="marginLeft:20rpx">立即下单</u-button>
					</view>
				</view>
				<!-- 加入购物车 和立即购买 -->
				<view class="slot_add" style="height: 80vh;padding-top: 30rpx;overflow: hidden;" v-if="showModel">
					<u-popup :show="showModel" @close="showModel=false"
						customStyle='min-height:80vh;padding-top:10rpx;overflow: hidden;' round='30rpx' mode="bottom"
						:closeable='true'>
						<scroll-view scroll-y="true" style="height:80vh;">
							<view>
								<view class="flexJBC" style="height:60vh;">
									<view class="left" style="height:60vh;" v-if="info.spec_type==1">
										<scroll-view scroll-y="true" style="min-height:100%;;background-color:#f4f4f4">
											<!-- 左侧列表 -->
											<view class=" center paddingLR32" v-for="(item,index) in info.new_attr"
												:key="index"
												:style="activenew_attr==index?'background-color: #fff':'background-color:#f4f4f4'"
												@click="activenew_attr=index" style="padding: 12rpx 32rpx;">
												<image :src="item.image" mode="aspectFill"
													style="width:96rpx;height: 96rpx;border-radius: 8rpx;"></image>
												<view class="">{{item.name}}</view>
											</view>
										</scroll-view>
									</view>
									<view class="right padding32" style="flex: 1;height:60vh;padding-top:15rpx;">
										<view class="flex" style="margin-bottom: 0rpx;">
											<image
												:src="info.spec_type==1?info.new_attr[activenew_attr].image:info.image"
												mode="aspectFill"
												style="width:240rpx;height: 240rpx;border-radius: 20rpx;">
											</image>

											<view style="flex: 1;margin-left: 28rpx;">
												<!-- 多规格批发 右侧 批发  -->
												<view class="homeRed fontS40" style="height: 240rpx;"
													v-if="info.is_start_wholesale==1 && info.spec_type==1">
													<view style="margin-bottom: 12rpx;">
														<view class="">
															<view>
																<text class="fontS28">￥</text>
																{{info.new_attr[activenew_attr].wholesale_end_price}}
															</view>
															<view>
																~
															</view>
															<view class="">
																<text class="fontS28">￥</text>
																{{info.new_attr[activenew_attr].wholesale_start_price}}
															</view>
														</view>
														<view class="co9 fontS24" style='margin-top: 8rpx;'>
															{{info.new_attr[activenew_attr].wholesale_number}}{{info.unit_name}}起批
														</view>
														<view class="fuzhucolor fontS20" style="color: #FFC047;">
															大批量购买请联系客服*</view>
													</view>
												</view>
												<!-- 单规格批发 右侧  -->
												<view class="homeRed fontS40" style="height: 240rpx;"
													v-if="(info.is_start_wholesale==1) && ( info.spec_type==0)">

													<view style="margin-bottom: 12rpx;">
														<view class="">
															<view>
																<text class="fontS28">￥</text>
																{{info.attrDetails[0].wholesale_start_price }}
															</view>
															<view>
																~
															</view>
															<view class="">
																<text class="fontS28">￥</text>
																{{info.attrDetails[0].wholesale_end_price}}
															</view>
														</view>
														<view class="co9 fontS24" style='margin-top: 8rpx;'>
															{{info.attrDetails[0].wholesale_number}}{{info.unit_name}}起批
														</view>
														<view class="fuzhucolor fontS20" style="color: #FFC047;">
															大批量购买请联系客服*</view>
													</view>
												</view>
											</view>
										</view>


										<!-- 弹窗底部规格 -->
										<scroll-view scroll-y="true" style='height: 72%;'>
											<!-- 多规格 批发不批发都在这里 -->
											<view v-if="info.spec_type==1">
												<view class="flexJBC"
													v-for="(item,index) in info.new_attr[activenew_attr].attr"
													:key="index" style="">
													<view class="" style="width: 100%;">
														<view class="">
															{{item.attrDetails.detail}}
														</view>
														<view class="flexJBC"
															style=" align-items: flex-end;margin-bottom: 42rpx;"
															v-for="itemm in item.attrDetails.data">
															<view class="">
																<view class="flex"
																	style='margin: 5rpx 0 0rpx;width: 100%;'>
																	<view class="co9 fontS24">
																		{{itemm.warehouse_type_name}}库存 {{itemm.stock}}
																	</view>
																</view>
																<view class="fuzhucolor fontS24"
																	v-if='itemm.is_start_wholesale==1 && (itemm.num<itemm.wholesale.setting_seller_data[0].small_number && itemm.num>0)  '>
																	未达到起批量
																</view>
																<!-- 批发-->
																<view class="" v-if='itemm.is_start_wholesale==1'
																	style="margin-top: 20rpx;">
																	<view class="flex"
																		v-for="at in itemm.wholesale.setting_seller_data">
																		<view class="co3 fontS24" style="width:180rpx;">
																			{{at.small_number}}~{{at.big_number}}{{info.unit_name}}
																		</view>
																		<view class="homeRed">
																			￥{{at.wholesale_price}}
																		</view>
																	</view>
																</view>
																<!-- 单独购买 -->
																<view class="homeRed" v-else style="margin-top: 20rpx;">
																	￥{{itemm.price}}
																</view>
															</view>
															<u-number-box :min="0" :max="itemm.stock" integer
																bgColor="#fff" inputWidth='80rpx' style='height: 48rpx;'
																v-model="itemm.num" @change='stepChange'>
															</u-number-box>
														</view>
													</view>
												</view>
											</view>
											<!-- 单规格 批发   info.spec_type==0 && info.is_start_wholesale==1-->
											<view v-if="info.spec_type==0 ">
												<view class="flexJBC" v-for="(item,index) in info.attrDetails"
													:key="index">
													<view class="" style="width: 100%;">
														<view class="flexJBC"
															style=" align-items: flex-end;margin-bottom: 42rpx;"
															v-for="itemm in item.data">
															<view class="">
																<view class="flex" style='margin: 5rpx 0 20rpx;'>
																	<view class="co9">{{itemm.warehouse_type_name}}库存
																		{{itemm.stock}}
																	</view>
																	<view style="margin-left: 10rpx;" class="fuzhucolor"
																		v-if='itemm.is_start_wholesale==1 && (itemm.num<itemm.wholesale.setting_seller_data[0].small_number && itemm.num>0)  '>
																		未达到起批量
																	</view>
																</view>
																<!-- 批发-->
																<view class="" v-if='itemm.is_start_wholesale==1'>
																	<view class="flex"
																		v-for="at in itemm.wholesale.setting_seller_data">
																		<view class="co3 fontS24"
																			style="min-width:150rpx;padding-right: 20rpx;box-sizing: border-box;">
																			{{at.small_number}}~{{at.big_number}}{{info.unit_name}}
																		</view>
																		<view class="homeRed" style="">
																			￥{{at.wholesale_price}}
																		</view>
																	</view>
																</view>
																<!-- 单独购买 -->
																<view class="homeRed" v-else>
																	￥{{itemm.price}}
																</view>
															</view>
															<u-number-box :min="0" :max="itemm.stock" integer
																bgColor="#fff" inputWidth='80rpx'
																style='height: 48rpx;margin-left: 100rpx;'
																v-model="itemm.num" @change='stepChange'>
															</u-number-box>
														</view>
													</view>
												</view>
											</view>
										</scroll-view>



									</view>
								</view>
								<view style="padding:40rpx 4%;height: 52rpx;line-height: 52rpx;" class="flexJBC">
									<!-- 多规格 -->
									<view class="fontS24 co9" v-if="info.spec_type==1">
										已选{{goodsTypeNum}}种{{allMum}}个
									</view>
									<!-- 单规格 -->
									<view class="fontS24 co9" v-else>
										已选{{allMum}}个
									</view>
									<!-- 商品金额如果按钮为未点击的转态 影藏 -->
									<view v-if="info.spec_type==1">
										<!-- v-if="info.is_start_wholesale==1?allMum>=info.number_wholesale_nunber:allMum>0" -->
										<view class="flex" v-if="info.is_start_wholesale==1 && showAllprice">
											<view class="">
												商品金额：
											</view>
											<view class="homeRed fontS40">
												￥{{allprice}}
											</view>
										</view>
									</view>
									<view class="flex" v-if="info.spec_type==0 && showAllprice">
										<view class="">
											商品金额：
										</view>
										<view class="homeRed fontS40">
											￥{{allprice}}
										</view>
									</view>
								</view>
								<view style="margin:0rpx 4% 0rpx;">
									<!-- 多规格  批发数量如果没有大于等于购买数量才显示    不是批发的多规格总数量大于1就可以购买-->
									<u-button class="btn fontS32 bgcred cof" customStyle="borderRadius:40rpx"
										@click="addCartOrGoPay"
										:disabled="info.is_start_wholesale==1?((!showAllprice)||(allMum<=0)):allMum<=0">
										确定
									</u-button>
								</view>
							</view>
						</scroll-view>
					</u-popup>
				</view>
			</view>
		</view>
		<u-loading-page loading-text="loading..." v-else :loading='true' bgColor='#f5f5f5'></u-loading-page>
		<Coupon :showCoupon='showCoupon' @showCouponClose='showCouponClose' :copuonList='info.coupon?info.coupon:[]' />
	</view>
</template>
<script>
	import List from '@/componentes/list.vue'
	import Coupon from '@/componentes/coupon.vue'
	import Swiper from '../../componentes/z-swiper/index.vue'
	import Certification from '@/componentes/certification.vue'
	export default {
		components: {
			List,
			Coupon,
			Swiper,
			Certification
		},

		data() {
			return {
				showAllprice: false, //是否显示总金额（批发，当用户添加的数量没有达到批发的价格时不计算价格）
				showCoupon: false, //优惠券弹窗
				allMum: 0, //已选中几个
				goodsTypeNum: 0, //已选几种
				allprice: 0, //总价格
				activenew_attr: 0, //多规格 当前选中左侧列表的大分类
				code: 200, //code 为208表示商品失效
				shixiaoTuijianList: [], //失效推荐列表
				type: 1, //1加入购物车  2是立即购买 
				// atteritem: {}, //当前选中商品规格的数据列表
				// atter: [], //当前选中的商品规格
				num: 1, //购买或加入购物车数量(单规格)
				page: 1,
				findProductComment: '', //评论列表
				swiperCurrent: 0,
				info: {},
				pageLoading: true,
				id: "", //商品id
				showModel: false, //加入购物车和立即购买弹窗
				inputValue: '',
				swiperList: [],
			}
		},
		onLoad(option) {
			this.id = option.id ? option.id : 76;
			this.findProduct()
			this.getInfo()
		},
		onReachBottom() {
			if (this.code == 208) {
				this.page++;
				this.getTuijianList()
			}
		},
		methods: {
			// 评论列表
			findProduct() {
				this.$my.post('/index/storeComment/findProductComment', {
					page: 1,
					limit: 2,
					product_id: this.id,
				}).then(res => {
					if (res.code == 200) {
						this.findProductComment = res.data
					}
				})
			},
			// 关闭优惠卷弹窗
			showCouponClose(val) {
				this.showCoupon = val
			},
			//客服
			gokefu() {
				if (this.info.im_data.id) {
					this.$my.post('/index/Im/recordChatHistory', {
						to_user_id: this.info.im_data.id
					}).then(res => {
						if (res.code == 200) {
							this.$my.go('/myPackageA/goodsAndFacton/kefu?id=' + this.info.im_data.tencent_user_id)
						}
					})
				} else if (!uni.getStorageSync('token')) {
					this.$my.go('/pages/login/login')
				} else {
					this.$my.toast('当前没有客服在线')
				}
			},
			stepChange(e) {
				this.$nextTick(() => {
					// 批发
					let allnum = 0
					let alltypeNum = 0
					// 多规格
					this.allMum = 0;
					this.goodsTypeNum = 0;
					this.allprice = 0;
					let showAllprice = true; // 如何有一个商品的数量没有达到起批量就不展示价格
					if (this.info.spec_type == 1) {
						// 批发
						if (this.info.is_start_wholesale == 1) {
							console.log(this.info.new_attr, 'this.info.new_attr')
							this.info.new_attr.forEach(item => {
								item.attr.forEach(item1 => {
									let attrDetails = item1.attrDetails
									let goodsTypeNum = false; //计算购买的种类
									attrDetails.data.forEach(item3 => {
										// 批发 
										if (item3.is_start_wholesale == 1) {
											console.log(item3.num, '12')
											if (item3.num > 0) {
												goodsTypeNum = true
												this.allMum += item3.num
												item3.wholesale.setting_seller_data
													.forEach((item, index) => {
														item.big_number = Number(item
															.big_number)
														item.small_number = Number(item
															.small_number)
														if ((item3.num >= item
																.small_number) && (
																item3.num <= item
																.big_number)) {
															this.$set(item3,
																'allprice', item
																.wholesale_price *
																item3.num)
														} else if (item3.num > item
															.big_number) {
															this.$set(item3,
																'allprice', item
																.wholesale_price *
																item3.num)
														}
													})
												// 如何有一个商品的数量没有达到起批量就不展示价格
												if ((item3.num < item3.wholesale
														.setting_seller_data[0]
														.small_number) && (item3.num !=
													0)) {
													showAllprice = false
												}
												this.allprice += Number(item3.allprice)
											}
										} else {
											if (item3.num > 0) {
												goodsTypeNum = true
												this.allMum += item3.num
												this.allprice += (Number(item3.num) *Number(item3.price))
											} 
										}
										console.log(goodsTypeNum, 'goodsTypeNum')

									})
									goodsTypeNum ? this.goodsTypeNum++ : ""
									this.showAllprice = showAllprice

									// console.log(showAllprice,goodsTypeNum,'showAllprice')
								})
							})
						} else {
							// 不是批发的多规格
							this.info.new_attr.forEach(item => {
								item.attr.forEach(item1 => {
									let attrDetails = item1.attrDetails
									attrDetails.data.forEach(item3 => {
										if (item3.num > 0) {
											this.goodsTypeNum++;
											this.allMum += item3.num;
										}
										this.showAllprice = this.allMum > 0
										this.allprice += (Number(item3.num) * Number(item3
											.price))
									})
								})
							})
						}
					} else {
						// 单规格

						if (this.info.is_start_wholesale == 1) {
							this.info.attrDetails.forEach(item => {
								item.data.forEach(item3 => {
									let attrDetails = item3
									// 批发 
									console.log(item3, 'item3')
									if (item3.is_start_wholesale == 1) {
										if (item3.num > 0) {
											this.allMum += item3.num
											item3.wholesale.setting_seller_data.forEach((item,
												index) => {
												item.big_number = Number(item.big_number)
												item.small_number = Number(item
													.small_number)
												if ((item3.num >= item.small_number) && (
														item3.num <= item.big_number)) {
													this.$set(item3, 'allprice', item
														.wholesale_price * item3.num)
												} else if (item3.num > item.big_number) {
													this.$set(item3, 'allprice', item
														.wholesale_price * item3.num)
												}
											})
											// 如何有一个商品的数量没有达到起批量就不展示价格
											if ((item3.num < item3.wholesale.setting_seller_data[0]
													.small_number) && (item3.num != 0)) {
												showAllprice = false
											}
											this.allprice += Number(item3.allprice)
										}
									} else {
										if (item3.num > 0) {
											this.allMum += item3.num
										}
										this.showAllprice = this.allMum > 0
										this.allprice += (Number(item3.num) * Number(item3.price))
									}
									this.showAllprice = showAllprice

								})
							})
						} else {
							// 不是批发的单规格
							this.info.attrDetails.forEach(item => {
								item.data.forEach(item3 => {
									// let attrDetails =item1
									// attrDetails.data.forEach(item3=>{
									if (item3.num > 0) {
										this.allMum += item3.num
									}
									this.showAllprice = this.allMum > 0
									this.allprice += (Number(item3.num) * Number(item3.price))
									// })
								})
							})
						}



						// if (this.info.is_start_wholesale == 1) {
						// 	// 批发计算价格
						// 	this.info.wholesale.setting_seller_data.forEach((item, index) => {
						// 		item.big_number = Number(item.big_number)
						// 		item.small_number = Number(item.small_number)
						// 		// console.log(this.allMum, this.allMum >= item.small_number, 8888888888)
						// 		if ((this.num >= item.small_number) && (this.num <= item.big_number)) {
						// 			this.allprice = (item.wholesale_price * this.num).toFixed(2)
						// 		} else if (this.num > item.big_number) {
						// 			this.allprice = (item.wholesale_price * this.num).toFixed(2)
						// 		}
						// 	})
						// }else{
						// 	// 不是批发计算价格
						// 	this.allprice =(this.num*this.info.attrDetails[0].price) .toFixed(2)
						// }
					}

					// 是否企业
					if (this.$store.state.company_status == 0) {
						this.allprice = '???'
					} else {
						this.allprice = this.allprice.toFixed(2)
					}
				})
			},
			// 失效找相似
			getTuijianList() {
				this.$my.post('/index/product/similar/list', {
					page: this.page,
					limit: 10,
					goods_id: this.id
				}).then(res => {
					if (res.code == 200) {
						this.shixiaoTuijianList = this.shixiaoTuijianList.concat(res.data.data)
					}
				})
			},
			// 1加入购物车 或者 2直接购买
			addCartOrGoPay() {

				// 获取用户个人信息
				this.$my.get('/index/user/get_user_info').then(res => {
					if (res.code == 200) {
						uni.setStorageSync('userInfo', res.data)
						// 是否企业认证  0未认证1认证中2已拒绝3成功  
						if (res.data.company_status == 3) { //if(res.data.company_status==3)
							this.showModel = false
							// 获取所选规格
							let data = {
								data: []
							};
							// 多规格
							if (this.info.spec_type == 1) {
								this.info.new_attr.forEach(item => {
									item.attr.forEach(item1 => {
										let attrDetails = item1.attrDetails.data
										attrDetails.forEach(item2 => {
											if (item2.num > 0) {
												if (this.type == 1) {
													data.data.push({
														goods_id: item1.attrDetails
															.product_id,
														num: item2.num,
														sku_id: item2.id
													})
												} else {
													data.data.push({
														product_id: item1
															.attrDetails
															.product_id,
														number: item2.num,
														sku_id: item2.id
													})
												}
											}
										})

									})
								})
							} else {
								// 单规格加入购物车
								this.info.attrDetails.forEach(item => {
									item.data.forEach(item1 => {
										if (item1.num > 0) {
											if (this.type == 1) {
												data.data.push({
													goods_id: item.product_id,
													num: item1.num,
													sku_id: item1.id
												})
											} else {
												// 单规格立即购买
												data.data.push({
													product_id: item.product_id,
													number: item1.num,
													sku_id: item1.id
												})
											}
										}

									})
								})
							}
							data.data = JSON.stringify(data.data)
							if (this.type == 1) {
								this.$my.post('/index/cart/store', data).then(res => {
									this.$my.toast(res.message)
								})
							} else {
								// 立即购买   去购买订单页
								let address_id = '';
								this.$my.get('/index/user/get_address').then(res => {
									if (res.code == 200 && res.data.length > 0) {
										res.data.forEach(item => {
											if (item.is_default) {
												address_id = item.id
											}
										})
										address_id = address_id ? address_id : (res.data[0] ? res.data[0]
											.id : '')
									}
									this.$my.go('/pages/my/order/sureOrder?type=2&orderinfo=' + JSON
										.stringify(data) +
										'&address_id=' + address_id)
								})
							}
						} else {
							// 未认证
							this.$my.toast(res.data.company_status == 0 ? '你可以在页面顶部认证后继续下单' : res.data
								.company_status == 1 ? '企业认证中，通过后再继续下单吧' : '企业认证未通过，可在顶部重新申请')
							return
						}
					}
				})
			},
			// 点击规格
			attrLisClick(item, itemm) {
				if (!this.atter.includes(itemm.id)) {
					let id;
					this.atter.forEach((val, index) => {
						this.info.attrValue.forEach(val1 => {
							if (val == val1.id) {
								id = val1.attr_id
								if (id == itemm.attr_id) {
									this.atter.splice(index, 1)
									console.log(3, this.atter)
								} else {
									if (!this.atter.includes(itemm.id)) {
										this.atter.push(itemm.id)
									}
								}
							}
							if (!this.atter.includes(itemm.id)) {
								this.atter.push(itemm.id)
								console.log(2, this.atter)
							}
						})
					})
					if (this.atter.length == 0) {
						this.atter.push(itemm.id)
					}
				} else {
					this.atter.forEach((val, index) => {
						if (val == itemm.id) {
							this.atter.splice(index, 1)
							console.log(4, this.atter)
						}
					})
				}

				// 拿规格id
				if (this.atter.length == 2) {
					this.info.attrDetails.forEach(item => {
						let at = item.sku.split(',').map(Number)
						if (JSON.stringify(at.sort()) == JSON.stringify(this.atter.sort())) {
							if (this.info.is_start_wholesale == 0) {
								// 单独购买
								this.atteritem = item
							} else {
								this.atteritem = item
								// 批发
								this.info.wholesale.setting_seller_data.forEach((item, index) => {
									this.number = Number(this.number)
									item.big_number = Number(item.big_number)
									item.small_number = Number(item.small_number)
									if ((this.num >= item.small_number) && (this.num <= item.big_number)) {
										this.atteritem.price = item.wholesale_price
									} else if (this.num > item.big_number) {
										this.atteritem.price = item.wholesale_price
										console.log(item, index, this.num, 12, this.num >= item
											.small_number)
									}
								})
							}
						}
					})
				}
			},

			getInfo() {
				this.$my.post('/index/productDetail/findProduct', {
					product_id: this.id
				}).then(res => {
					this.pageLoading = false;
					this.code = res.code;
					if (res.code == 208) {
						this.getTuijianList()
					}
					if (res.code == 200) {
						this.info = res.data;
						// this.info.is_start_wholesale=0 
						// console.log(this.info.attrDetails[0].data[1].wholesale.setting_seller_data)
						// this.info.attrDetails[0].data[1].wholesale.setting_seller_data=[this.info.attrDetails[0].data[1].wholesale.setting_seller_data[1]]
						// this.info.new_attr[0].attr[1].attrDetails.data[0].wholesale.setting_seller_data=[this.info.new_attr[0].attr[1].attrDetails.data[0].wholesale.setting_seller_data[1]]
						// this.info.new_attr[0].attr[1].attrDetails.data[0].wholesale.setting_seller_data=[this.info.new_attr[0].attr[1].attrDetails.data[1].wholesale.setting_seller_data[1]]
						// 优惠券 
						this.info.coupon.forEach(item => {
							this.$set(item, 'showInfo', false)
						})
						// 批发 多规格
						if (this.info.spec_type == 1) {
							this.info.new_attr.forEach(item => {
								item.attr.forEach(item1 => {
									// 每一个规格的数量   item1.attrDetails 商品出错有时返回的字段是数组故有此判断
									if (item1.attrDetails.product_id) {
										item1.attrDetails.data.forEach(item2 => {
											// 每一个规格的数量
											this.$set(item2, 'num', 0)
										})
									}

								})
							})
						}
						// 单规格
						if (this.info.spec_type == 0) {
							this.info.attrDetails.forEach(item => {
								// 每一个规格的数量
								item.data.forEach(item2 => {
									// 每一个规格的数量
									this.$set(item2, 'num', 0)
								})
							})
						}
						// 商品详情图片样式修改
						this.info.content = this.info.content ? this.info.content.replace(/\<img/gi,
							'<img style="max-width:100%;height:auto" ') : '';
						// 顶部轮播图



						let sw = this.info.slider_image.split(',')
						sw.forEach(item => {
							let obj = {
								src: item,
								type: 'image'
							}
							this.swiperList.push(obj)
						})
						if (this.info.is_video) {
							let swp = this.info.video_link.split(',')
							swp.forEach(item => {
								let obj = {
									src: item,
									poster: item,
									type: 'video'
								}
								this.swiperList.push(obj)
							})
						}
					}
				})
			},
			// 收藏  和  取消收藏
			follow() {
				this.$my.post('/index/user/store_follow', {
					id: this.id,
					type: 2
				}).then(res => {
					if (res.message) this.$my.toast(res.message);
					if (res.code == 200) {
						this.getInfo()
					}
				})
			},
		}
	}
</script>
<style>
	page {
		padding-bottom: 90rpx;
	}
</style>
<style lang="scss" scoped>
	/deep/.uicon-arrow-left {
		top: -30rpx !important;
	}

	.item {
		/deep/.uicon-arrow-left {
			top: 0rpx !important;
		}
	}

	.skuBox {
		padding: 8rpx 8rpx;
		background: #EEEEEE;
	}

	/deep/.u-swiper__indicator {
		right: 20rpx;
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	/deep/ .ql-align-center {
		text-align: center !important;
	}

	/deep/ .u-number-box__minus {
		border-right: 1rpx solid #ccc;
		width: 48rpx;
	}

	/deep/.u-number-box__plus {
		border-left: 1rpx solid #ccc;
		width: 48rpx;
	}

	/deep/ .u-number-box {
		border: 2rpx solid #CCCCCC;
		border-radius: 16rpx;
		overflow: hidden;
	}

	// .swiperLi {
	// 	padding: 0rpx 20rpx;
	// 	height: 40rpx;
	// 	background: rgba(0, 0, 0, 0.4);
	// 	border-radius: 20rpx;
	// 	bottom: 24rpx;
	// 	right: 24rpx;
	// }

	/deep/.input_right {
		width: 100%;
		// border: 1px solid red;
		height: 80rpx;
		background-color: white;
		box-sizing: border-box;
		padding: 0 20rpx;

	}

	/deep/.u-navbar__content__right {
		left: 10%;
		padding-right: 0;
	}

	.content {
		.top {
			.top_left {
				margin-right: 20rpx;

			}
		}

		.container {
			padding: 44rpx 4% 0;
			background-color: rgb(245, 245, 245);

			.shop {
				.li {
					margin: 0 auto;
					// width: 90%;
					// height: 370rpx;
					background-color: white;
					border-radius: 16rpx;
					padding: 20rpx;
					box-sizing: border-box;

					.li_top {
						height: 80rpx;
						display: flex;



						.box_center {
							height: 100%;
							flex-grow: 1;
							// background-color: pink;
							margin: 0 20rpx;

							.score {
								color: #FFA848;
								margin-left: 8rpx;
							}

							.deal {
								margin-left: 20rpx;
							}
						}

						.box_right {
							.entry {
								width: 96rpx;
								height: 48rpx;
								padding: 0;
								line-height: 48rpx;
								color: $red;
								border: 2rpx solid $red;
								border-radius: 24rpx;
							}
						}
					}

					.li_center {
						height: 190rpx;
						// background-color: red;
						padding-top: 20rpx;
						padding-bottom: 12rpx;

						.li_img {
							min-width: 190rpx;
							height: 190rpx;
							margin-right: 18rpx;
							border-radius: 8rpx;
							overflow: hidden;
							position: relative;

							.money {
								position: absolute;
								width: 96rpx;
								height: 36rpx;
								background-color: rgba(0, 0, 0, 0.6);
								border-radius: 20rpx 0 0 0;
								right: 0;
								bottom: 0;
								color: white;
							}
						}
					}

				}
			}


		}

		.bottom {
			background-color: white;
			// height: 112rpx;
			padding: 16rpx 4%;
			justify-content: space-between;
			box-sizing: border-box;
			position: fixed;
			bottom: 0%;
			width: 100%;

			.bottom_btn {
				// width: 400rpx;
				// display: flex;
				// justify-content: space-between;

				button {
					margin: 0;
					border-radius: 68rpx;
					color: white;
				}

				/deep/button:nth-of-type(1) {
					background-color: #FFC047 !important;
				}

				.add {
					background-color: #FFC047 !important;
				}

				.topay {
					background-color: $red;
				}
			}
		}

		.slot {
			background-color: white;

			.slot_title {
				margin: 0 4%;
			}

			.li {
				height: 88rpx;
				margin: 0 4%;
				background-color: white;
				line-height: 88rpx;
				border-bottom: 2rpx solid #f1f1f1;

				&:last-child {
					margin-bottom: 110rpx;
				}
			}
		}

		.slot_add {
			.lis {
				height: 64rpx;
				line-height: 64rpx;
				margin-top: 20rpx;
				background: #EEEEEE;
				padding: 0 20rpx;
				box-sizing: border-box;
				border-radius: 32rpx;
				border: 1px solid #eee;
				margin-right: 24rpx;
				min-width: 120rpx;
				text-align: center;
			}

			.lisactive {
				background: #FFF4F4;
				border: 1px solid #DD2131
			}

		}


	}
</style>
